<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="com.hnas.core.util.PropertyUtil"%>
<%@page import="com.hnas.core.dto.DataBean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>红包列表</title>
<script type="text/javascript">
</script>
</head>
<body>
	<!-- 标题 -->
	<div class="titleBar m_b_20">
		<div class="tit fl b_l_e74a5f">
			<h3 class="cn">红包列表</h3>
			<span class="en">redpacket information</span>
		</div>
		<div class="fr"></div>
	</div>
	<!-- end 标题 -->

	<form method="post" action="${pageContext.request.contextPath }/backend/redpacket/search" name="searchForm"  >
  	<input type="hidden" name="pageNo" value="${dto.pageNo}">
  	<input type="hidden" name="totalCount" value="${dto.totalCount}">
	<!-- 查询 -->
	<div class="box_03 p_20 m_b_20">
		<table class="tb_style02" width="100%">
	        <tr>
	            <th>每页显示</th>
	            <td colspan="5">
	            	<input style="width:50px;" class="input_style2" type="text" placeholder="" id="pageSize" name="pageSize" value="${dto.pageSize}"> 条
	                <span style="margin-left:170px;">
	                	<input style="width:110px;" class="btn_brown02 m_r_12" type="button" name="searchData" id="searchData" value="查  询">
	               		<!-- <input style="width:110px;" class="btn_brown02 m_r_12" type="button" name="createData" id="createData" value="添 加"> -->
	                </span>
	            </td>
	         </tr>
		</table>
	</div>
	<!-- end 查询 -->
				
</form>

<div class="m_b_20">
	<table class="tb_style05" width="100%" style="table-layout:fixed;">
		<thead>
		<tr>
			<c:forEach items="${beans}" var="o">
			<c:if test="${o.display && !o.hidden}"><th>${o.title}</th></c:if>
			</c:forEach>
			<th width="100">操作</th>
		</tr>
		</thead>
		<tbody>
			<c:forEach items="${pg.list}" var="o">
			<tr>
				<c:forEach items="${beans}" var="o1">
					<c:if test="${o1.display && !o1.hidden}">
					<td style="word-wrap:break-word;"><%=String.valueOf(PropertyUtil.getValue(pageContext.getAttribute("o"),((DataBean)pageContext.getAttribute("o1")).getField())).replace("false","否").replace("true","是")%></td></c:if>
				</c:forEach>
					<td>
						<a href="#" class="c_3366cc btn showCouponDetail" id="${o.id }">查看详情</a>&nbsp;&nbsp;
						<%-- <a href="#" class="c_3366cc btn deleteData" id="${o.id }">删除</a> --%>
					</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
	<div class="searpage" align="right"><div>${pg.pageStr}</div></div><br/>
</div>
<script>
	function gotoJumpPage(){
		var jumpNum= $("#jumpNum").val();
		$("#search_page_size").val($("#id_page_size").val());
		gotoPage(jumpNum);
		return false;
	}
	function deleteData(id){
		var deleteURL = "${pageContext.request.contextPath }/backend/redpacket/del?id=" + id;
		alert(deleteURL);
	     $.ajax({
				url:deleteURL,
				type: 'POST',
				error: function(XMLHttpRequest, textStatus, errorThrown){
					//alert('加载数据异常。' + textStatus + "/" + errorThrown);
					$.dialog.alert({title:"删除",content:"加载数据异常"});
				},
				success: function(data){
					if(data.result==1) {
						//alert("删除成功");
						$.dialog.alert({title:"删除",content:"删除成功"});
						/** 删除后触发查询 **/
						query();
					} else {
						//alert("删除失败"+data.errorMessage);
						$.dialog.alert({title:"删除",content:"删除失败"+data.errorMessage});
					}
				}
			});
	}
	$(function(){
		$("#searchData").click(function(){
			/** 校验输入页数是否非法  **/
			var pageSize=$("#pageSize").val();
			var reg = new RegExp("^[0-9]*$");
			if($.trim(pageSize)!=""){
				if(!reg.test($.trim(pageSize))){
					alert("每页显示数请输入非负整数");
	 				return false;
				}
			}
			if($.trim(pageSize)==""){
				alert("每页显示数不应许为空");
				return false;
			}
			doSubmit();
		});
		
		/** 删除 **/
		$(".deleteData").click(function(){
			var id = $(this).attr("id");
			 $.dialog.confirm({title:"删除",content:"您确定要删除吗",callback:"deleteData('"+id+"');"});
		});
		/** 查看代金券详情 **/
		$(".showCouponDetail").click(function(){
			var rpId = $(this).attr("id");
			window.location.href = "${pageContext.request.contextPath }/backend/redpacket/showCoupons/"+rpId;
		})
	});
</script>
</body>
</html>